Return type | Name and parameters |
---|---|
boolean
|
any()
Iterates over the contents of a boolean Array, and checks whether any element is true. |
boolean
|
any(Closure predicate)
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element. |
boolean
|
asBoolean()
Coerces a boolean array to a boolean value. |
List
|
chop(int chopSizes)
Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes. |
boolean
|
contains(Object value)
Checks whether the array contains the given value. |
Number
|
count(Object value)
Counts the number of occurrences of the given value inside this array. |
boolean[]
|
each(Consumer consumer)
Iterates through a boolean[] passing each boolean to the given consumer. |
boolean[]
|
eachWithIndex(Closure closure)
Iterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure. |
boolean
|
equals(boolean[] right)
Compares the contents of this array to the contents of the given array. |
boolean
|
every()
Iterates over the contents of a boolean Array, and checks whether every element is true. |
boolean
|
every(Closure predicate)
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element. |
boolean
|
first()
Returns the first item from the boolean array. |
List
|
flatten()
Flattens an array. |
List
|
getAt(IntRange range)
Supports the subscript operator for a boolean array with an IntRange giving the desired indices. |
List
|
getAt(ObjectRange range)
Supports the subscript operator for a boolean array with an ObjectRange giving the desired indices. |
List
|
getAt(Range range)
Supports the subscript operator for a boolean array with a range giving the desired indices. |
List
|
getAt(Collection indices)
Supports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices. |
IntRange
|
getIndices()
Returns indices of the boolean array. |
boolean
|
head()
Returns the first item from the boolean array. |
boolean[]
|
init()
Returns the items from the boolean array excluding the last item. |
String
|
join()
Concatenates the string representation of each item in this array. |
String
|
join(String separator)
Concatenates the string representation of each item in this array, with the given String as a separator between each item. |
boolean
|
last()
Returns the last item from the boolean array. |
boolean[]
|
reverse()
Creates a new boolean array containing items which are the same as this array but in reverse order. |
boolean[]
|
reverse(boolean mutate)
Reverses the items in an array. |
boolean[]
|
reverseEach(Closure closure)
Iterates through a boolean[] in reverse order passing each boolean to the given closure. |
int
|
size()
Provides arrays with a size method similar to collections.
|
Stream
|
stream()
Returns a sequential Stream with the specified array as its source. |
boolean[]
|
swap(int i, int j)
Swaps two elements at the specified positions. |
boolean[]
|
tail()
Returns the items from the boolean array excluding the first item. |
List
|
toList()
Converts this array to a List of the same size, with each element added to the list. |
Set
|
toSet()
Converts this array to a Set, with each unique element added to the set. |
String
|
toString()
Returns the string representation of the given array. |
Iterates over the contents of a boolean Array, and checks whether any element is true.
boolean[] array1 = [false, true] assert array1.any() boolean[] array2 = [false] assert !array2.any()
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for at least one element.
boolean[] array = [true] assert array.any{ it } assert !array.any{ !it }
predicate
- the closure predicate used for matchingCoerces a boolean array to a boolean value. A boolean array is false if the array is of length 0, and true otherwise.
Chops the boolean array into pieces, returning lists with sizes corresponding to the supplied chop sizes. If the array isn't large enough, truncated (possibly empty) pieces are returned. Using a chop size of -1 will cause that piece to contain all remaining items from the array.
boolean[] array = [false, true, false] assert array.chop(1, 2) == [[false], [true, false]]
chopSizes
- the sizes for the returned piecesChecks whether the array contains the given value.
value
- the value being searched forCounts the number of occurrences of the given value inside this array.
Comparison is done using Groovy's == operator (using
compareTo(value) == 0
).
boolean[] array = [false, true, true] assert array.count(true) == 2
value
- the value being searched forIterates through a boolean[] passing each boolean to the given consumer.
boolean[] array = [false, true, false] String result = '' array.each{ result += it.toString()[0] } assert result == 'ftf'
consumer
- the consumer for each booleanIterates through a boolean[], passing each boolean and the element's index (a counter starting at zero) to the given closure.
boolean[] array = [false, true, false]
String result = ''
array.eachWithIndex{ item, index ->
result += "$index($item)" }
assert result == '0(false)1(true)2(false)'
closure
- a Closure to operate on each booleanCompares the contents of this array to the contents of the given array.
Example usage:
boolean[] array1 = [true, false] boolean[] array2 = [true, false] assert array1 !== array2 assert array1.equals(array2)
right
- the array being comparedIterates over the contents of a boolean Array, and checks whether every element is true.
boolean[] array1 = [false, true] assert !array1.every() boolean[] array2 = [true, true] assert array2.every()
Iterates over the contents of a boolean Array, and checks whether a predicate is valid for every element.
boolean[] array = [true] assert array.every{ it } assert !array.every{ !it }
predicate
- the closure predicate used for matchingReturns the first item from the boolean array.
boolean[] array = [true, false] assert array.first() == trueAn alias for
head()
.
Flattens an array. This array is added to a new collection.
It is an alias for toList()
but allows algorithms to be written which also
work on multidimensional arrays or non-arrays where flattening would be applicable.
boolean[] array = [false, true] assert array.flatten() == [false, true]
Supports the subscript operator for a boolean array with an IntRange giving the desired indices.
boolean[] array = [false, false, true, true, false] assert array[2..3] == [true, true] assert array[-2..-1] == [true, false] assert array[-1..-2] == [false, true]
range
- an IntRange indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with an ObjectRange giving the desired indices.
boolean[] array = [false, false, true, true, false] def range = new ObjectRange(2, 3) assert array[range] == [true, true]
range
- an ObjectRange indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with a range giving the desired indices.
boolean[] array = [false, true, false, true, false, true] assert array[2..<2] == [] // EmptyRange assert array[(0..5.5).step(2)] == [false, false, false] // NumberRange assert array[(1..5.5).step(2)] == [true, true, true] // NumberRange
range
- a range indicating the indices for the items to retrieveSupports the subscript operator for a boolean array with a (potentially nested) collection giving the desired indices.
boolean[] array = [false, false, true, true, false] assert array[2, 3] == [true, true] assert array[0, 0..1, [1, [-1]]] == [false, false, false, false, false]
indices
- a collection of indices for the items to retrieveReturns indices of the boolean array.
boolean[] array = [false, true] assert array.indices == 0..1
Returns the first item from the boolean array.
boolean[] array = [true, false] assert array.head() == trueAn alias for
first()
.
Returns the items from the boolean array excluding the last item.
boolean[] array = [true, false, true] def result = array.init() assert result == [true, false] assert array.class.componentType == result.class.componentType
Concatenates the string representation of each item in this array.
Concatenates the string representation of each item in this array, with the given String as a separator between each item.
separator
- a String separatorReturns the last item from the boolean array.
boolean[] array = [true, false, true] assert array.last() == true
Creates a new boolean array containing items which are the same as this array but in reverse order.
boolean[] array = [false, true] assert array.reverse() == [true, false]
Reverses the items in an array. If mutate is true, the original array is modified in place and returned. Otherwise, a new array containing the reversed items is produced.
boolean[] array = [false, true, true] def yarra = array.reverse(true) assert array == [true, true, false] assert yarra == [true, true, false] assert array === yarra yarra = array.reverse(false) assert array !== yarra assert array == [true, true, false] assert yarra == [false, true, true]
mutate
- true
if the array itself should be reversed in place, false
if a new array should be createdIterates through a boolean[] in reverse order passing each boolean to the given closure.
boolean[] array = [false, true, true] String result = '' array.reverseEach{ result += it } assert result == 'truetruefalse'
closure
- the closure applied on each booleanProvides arrays with a size
method similar to collections.
boolean[] array = [true, false, true] assert array.size() == 3
Returns a sequential Stream with the specified array as its source.
Stream
for the arraySwaps two elements at the specified positions.
Example:
assert ([false, true, false, true] as boolean[]) == ([false, false, true, true] as boolean[]).swap(1, 2)
i
- a positionj
- a positionReturns the items from the boolean array excluding the first item.
boolean[] array = [true, false, true] def result = array.tail() assert result == [false, true] assert array.class.componentType == result.class.componentType
Converts this array to a List of the same size, with each element added to the list.
Converts this array to a Set, with each unique element added to the set.
boolean[] array = [true, false, true] Set expected = [true, false] assert array.toSet() == expected
Returns the string representation of the given array.
boolean[] array = [false, true, false] assert array.toString() == '[false, true, false]'